package com.dyc.maitaole.controller;


import com.dyc.maitaole.entity.Brand;
import com.dyc.maitaole.entity.Category;
import com.dyc.maitaole.service.CategoryBrandService;
import com.dyc.maitaole.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/cbrand")
public class CategoryBrandController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CategoryBrandService categoryBrandService;

    @RequestMapping("/brandlist")
    public ModelAndView findAllBrand(@RequestParam(name = "categoryId", defaultValue = "1") Integer categoryId) {
        List<Category> categories = categoryService.findAllCategories();
        List<Brand> brands = categoryBrandService.findAllBrandByCategoryId(categoryId);
        ModelAndView modelAndView = new ModelAndView("/index.jsp");
        modelAndView.addObject("categories", categories);
        modelAndView.addObject("brands", brands);
        return modelAndView;
    }
}
